#ifndef __UP_GD32F4xx_H__
#define __UP_GD32F4xx_H__

#include "gd32f4xx.h"

#define USART0_DMA_ENABLE 0
#define USART1_DMA_ENABLE 0
#define USART2_DMA_ENABLE 0
#define USART5_DMA_ENABLE 0

#define SPI0_ENABLE 0
#define SPI1_ENABLE 0
#define SPI2_ENABLE 0
#define SPI3_ENABLE 0
#define SPI4_ENABLE 1
#define SPI5_ENABLE 0
#define SPI6_ENABLE 0

// ---------------------------------------
typedef struct 
{
    uint32_t port;
    uint32_t pin;
    uint32_t af;
    rcu_periph_enum rcu_gpio;
} UP_GPIO;

#define PA0 (UP_GPIO){GPIOA, GPIO_PIN_0, 0, RCU_GPIOA}
#define PA1 (UP_GPIO){GPIOA, GPIO_PIN_1, 0, RCU_GPIOA}
#define PA2 (UP_GPIO){GPIOA, GPIO_PIN_2, 0, RCU_GPIOA}
#define PA3 (UP_GPIO){GPIOA, GPIO_PIN_3, 0, RCU_GPIOA}
#define PA4 (UP_GPIO){GPIOA, GPIO_PIN_4, 0, RCU_GPIOA}
#define PA5 (UP_GPIO){GPIOA, GPIO_PIN_5, 0, RCU_GPIOA}
#define PA6 (UP_GPIO){GPIOA, GPIO_PIN_6, 0, RCU_GPIOA}
#define PA7 (UP_GPIO){GPIOA, GPIO_PIN_7, 0, RCU_GPIOA}
#define PA8 (UP_GPIO){GPIOA, GPIO_PIN_8, 0, RCU_GPIOA}
#define PA9 (UP_GPIO){GPIOA, GPIO_PIN_9, 0, RCU_GPIOA}
#define PA10 (UP_GPIO){GPIOA, GPIO_PIN_10, 0, RCU_GPIOA}
#define PA11 (UP_GPIO){GPIOA, GPIO_PIN_11, 0, RCU_GPIOA}
#define PA12 (UP_GPIO){GPIOA, GPIO_PIN_12, 0, RCU_GPIOA}
#define PA13 (UP_GPIO){GPIOA, GPIO_PIN_13, 0, RCU_GPIOA}
#define PA14 (UP_GPIO){GPIOA, GPIO_PIN_14, 0, RCU_GPIOA}
#define PA15 (UP_GPIO){GPIOA, GPIO_PIN_15, 0, RCU_GPIOA}

#define PB0 (UP_GPIO){GPIOB, GPIO_PIN_0, 0, RCU_GPIOB}
#define PB1 (UP_GPIO){GPIOB, GPIO_PIN_1, 0, RCU_GPIOB}
#define PB2 (UP_GPIO){GPIOB, GPIO_PIN_2, 0, RCU_GPIOB}
#define PB3 (UP_GPIO){GPIOB, GPIO_PIN_3, 0, RCU_GPIOB}
#define PB4 (UP_GPIO){GPIOB, GPIO_PIN_4, 0, RCU_GPIOB}
#define PB5 (UP_GPIO){GPIOB, GPIO_PIN_5, 0, RCU_GPIOB}
#define PB6 (UP_GPIO){GPIOB, GPIO_PIN_6, 0, RCU_GPIOB}
#define PB7 (UP_GPIO){GPIOB, GPIO_PIN_7, 0, RCU_GPIOB}
#define PB8 (UP_GPIO){GPIOB, GPIO_PIN_8, 0, RCU_GPIOB}
#define PB9 (UP_GPIO){GPIOB, GPIO_PIN_9, 0, RCU_GPIOB}
#define PB10 (UP_GPIO){GPIOB, GPIO_PIN_10, 0, RCU_GPIOB}
#define PB11 (UP_GPIO){GPIOB, GPIO_PIN_11, 0, RCU_GPIOB}
#define PB12 (UP_GPIO){GPIOB, GPIO_PIN_12, 0, RCU_GPIOB}
#define PB13 (UP_GPIO){GPIOB, GPIO_PIN_13, 0, RCU_GPIOB}
#define PB14 (UP_GPIO){GPIOB, GPIO_PIN_14, 0, RCU_GPIOB}
#define PB15 (UP_GPIO){GPIOB, GPIO_PIN_15, 0, RCU_GPIOB}

#define PC0 (UP_GPIO){GPIOC, GPIO_PIN_0, 0, RCU_GPIOC}
#define PC1 (UP_GPIO){GPIOC, GPIO_PIN_1, 0, RCU_GPIOC}
#define PC2 (UP_GPIO){GPIOC, GPIO_PIN_2, 0, RCU_GPIOC}
#define PC3 (UP_GPIO){GPIOC, GPIO_PIN_3, 0, RCU_GPIOC}
#define PC4 (UP_GPIO){GPIOC, GPIO_PIN_4, 0, RCU_GPIOC}
#define PC5 (UP_GPIO){GPIOC, GPIO_PIN_5, 0, RCU_GPIOC}
#define PC6 (UP_GPIO){GPIOC, GPIO_PIN_6, 0, RCU_GPIOC}
#define PC7 (UP_GPIO){GPIOC, GPIO_PIN_7, 0, RCU_GPIOC}
#define PC8 (UP_GPIO){GPIOC, GPIO_PIN_8, 0, RCU_GPIOC}
#define PC9 (UP_GPIO){GPIOC, GPIO_PIN_9, 0, RCU_GPIOC}
#define PC10 (UP_GPIO){GPIOC, GPIO_PIN_10, 0, RCU_GPIOC}
#define PC11 (UP_GPIO){GPIOC, GPIO_PIN_11, 0, RCU_GPIOC}
#define PC12 (UP_GPIO){GPIOC, GPIO_PIN_12, 0, RCU_GPIOC}
#define PC13 (UP_GPIO){GPIOC, GPIO_PIN_13, 0, RCU_GPIOC}
#define PC14 (UP_GPIO){GPIOC, GPIO_PIN_14, 0, RCU_GPIOC}
#define PC15 (UP_GPIO){GPIOC, GPIO_PIN_15, 0, RCU_GPIOC}

#define PD0 (UP_GPIO){GPIOD, GPIO_PIN_0, 0, RCU_GPIOD}
#define PD1 (UP_GPIO){GPIOD, GPIO_PIN_1, 0, RCU_GPIOD}
#define PD2 (UP_GPIO){GPIOD, GPIO_PIN_2, 0, RCU_GPIOD}
#define PD3 (UP_GPIO){GPIOD, GPIO_PIN_3, 0, RCU_GPIOD}
#define PD4 (UP_GPIO){GPIOD, GPIO_PIN_4, 0, RCU_GPIOD}
#define PD5 (UP_GPIO){GPIOD, GPIO_PIN_5, 0, RCU_GPIOD}
#define PD6 (UP_GPIO){GPIOD, GPIO_PIN_6, 0, RCU_GPIOD}
#define PD7 (UP_GPIO){GPIOD, GPIO_PIN_7, 0, RCU_GPIOD}
#define PD8 (UP_GPIO){GPIOD, GPIO_PIN_8, 0, RCU_GPIOD}
#define PD9 (UP_GPIO){GPIOD, GPIO_PIN_9, 0, RCU_GPIOD}
#define PD10 (UP_GPIO){GPIOD, GPIO_PIN_10, 0, RCU_GPIOD}
#define PD11 (UP_GPIO){GPIOD, GPIO_PIN_11, 0, RCU_GPIOD}
#define PD12 (UP_GPIO){GPIOD, GPIO_PIN_12, 0, RCU_GPIOD}
#define PD13 (UP_GPIO){GPIOD, GPIO_PIN_13, 0, RCU_GPIOD}
#define PD14 (UP_GPIO){GPIOD, GPIO_PIN_14, 0, RCU_GPIOD}
#define PD15 (UP_GPIO){GPIOD, GPIO_PIN_15, 0, RCU_GPIOD}

#define PE0 (UP_GPIO){GPIOE, GPIO_PIN_0, 0, RCU_GPIOE}
#define PE1 (UP_GPIO){GPIOE, GPIO_PIN_1, 0, RCU_GPIOE}
#define PE2 (UP_GPIO){GPIOE, GPIO_PIN_2, 0, RCU_GPIOE}
#define PE3 (UP_GPIO){GPIOE, GPIO_PIN_3, 0, RCU_GPIOE}
#define PE4 (UP_GPIO){GPIOE, GPIO_PIN_4, 0, RCU_GPIOE}
#define PE5 (UP_GPIO){GPIOE, GPIO_PIN_5, 0, RCU_GPIOE}
#define PE6 (UP_GPIO){GPIOE, GPIO_PIN_6, 0, RCU_GPIOE}
#define PE7 (UP_GPIO){GPIOE, GPIO_PIN_7, 0, RCU_GPIOE}
#define PE8 (UP_GPIO){GPIOE, GPIO_PIN_8, 0, RCU_GPIOE}
#define PE9 (UP_GPIO){GPIOE, GPIO_PIN_9, 0, RCU_GPIOE}
#define PE10 (UP_GPIO){GPIOE, GPIO_PIN_10, 0, RCU_GPIOE}
#define PE11 (UP_GPIO){GPIOE, GPIO_PIN_11, 0, RCU_GPIOE}
#define PE12 (UP_GPIO){GPIOE, GPIO_PIN_12, 0, RCU_GPIOE}
#define PE13 (UP_GPIO){GPIOE, GPIO_PIN_13, 0, RCU_GPIOE}
#define PE14 (UP_GPIO){GPIOE, GPIO_PIN_14, 0, RCU_GPIOE}
#define PE15 (UP_GPIO){GPIOE, GPIO_PIN_15, 0, RCU_GPIOE}

#define PF0 (UP_GPIO){GPIOF, GPIO_PIN_0, 0, RCU_GPIOF}
#define PF1 (UP_GPIO){GPIOF, GPIO_PIN_1, 0, RCU_GPIOF}
#define PF2 (UP_GPIO){GPIOF, GPIO_PIN_2, 0, RCU_GPIOF}
#define PF3 (UP_GPIO){GPIOF, GPIO_PIN_3, 0, RCU_GPIOF}
#define PF4 (UP_GPIO){GPIOF, GPIO_PIN_4, 0, RCU_GPIOF}
#define PF5 (UP_GPIO){GPIOF, GPIO_PIN_5, 0, RCU_GPIOF}
#define PF6 (UP_GPIO){GPIOF, GPIO_PIN_6, 0, RCU_GPIOF}
#define PF7 (UP_GPIO){GPIOF, GPIO_PIN_7, 0, RCU_GPIOF}
#define PF8 (UP_GPIO){GPIOF, GPIO_PIN_8, 0, RCU_GPIOF}
#define PF9 (UP_GPIO){GPIOF, GPIO_PIN_9, 0, RCU_GPIOF}
#define PF10 (UP_GPIO){GPIOF, GPIO_PIN_10, 0, RCU_GPIOF}
#define PF11 (UP_GPIO){GPIOF, GPIO_PIN_11, 0, RCU_GPIOF}
#define PF12 (UP_GPIO){GPIOF, GPIO_PIN_12, 0, RCU_GPIOF}
#define PF13 (UP_GPIO){GPIOF, GPIO_PIN_13, 0, RCU_GPIOF}
#define PF14 (UP_GPIO){GPIOF, GPIO_PIN_14, 0, RCU_GPIOF}
#define PF15 (UP_GPIO){GPIOF, GPIO_PIN_15, 0, RCU_GPIOF}

#define PG0 (UP_GPIO){GPIOG, GPIO_PIN_0, 0, RCU_GPIOG}
#define PG1 (UP_GPIO){GPIOG, GPIO_PIN_1, 0, RCU_GPIOG}
#define PG2 (UP_GPIO){GPIOG, GPIO_PIN_2, 0, RCU_GPIOG}
#define PG3 (UP_GPIO){GPIOG, GPIO_PIN_3, 0, RCU_GPIOG}
#define PG4 (UP_GPIO){GPIOG, GPIO_PIN_4, 0, RCU_GPIOG}
#define PG5 (UP_GPIO){GPIOG, GPIO_PIN_5, 0, RCU_GPIOG}
#define PG6 (UP_GPIO){GPIOG, GPIO_PIN_6, 0, RCU_GPIOG}
#define PG7 (UP_GPIO){GPIOG, GPIO_PIN_7, 0, RCU_GPIOG}
#define PG8 (UP_GPIO){GPIOG, GPIO_PIN_8, 0, RCU_GPIOG}
#define PG9 (UP_GPIO){GPIOG, GPIO_PIN_9, 0, RCU_GPIOG}
#define PG10 (UP_GPIO){GPIOG, GPIO_PIN_10, 0, RCU_GPIOG}
#define PG11 (UP_GPIO){GPIOG, GPIO_PIN_11, 0, RCU_GPIOG}
#define PG12 (UP_GPIO){GPIOG, GPIO_PIN_12, 0, RCU_GPIOG}
#define PG13 (UP_GPIO){GPIOG, GPIO_PIN_13, 0, RCU_GPIOG}
#define PG14 (UP_GPIO){GPIOG, GPIO_PIN_14, 0, RCU_GPIOG}
#define PG15 (UP_GPIO){GPIOG, GPIO_PIN_15, 0, RCU_GPIOG}

#define PH0 (UP_GPIO){GPIOH, GPIO_PIN_0, 0, RCU_GPIOH}
#define PH1 (UP_GPIO){GPIOH, GPIO_PIN_1, 0, RCU_GPIOH}
#define PH2 (UP_GPIO){GPIOH, GPIO_PIN_2, 0, RCU_GPIOH}
#define PH3 (UP_GPIO){GPIOH, GPIO_PIN_3, 0, RCU_GPIOH}
#define PH4 (UP_GPIO){GPIOH, GPIO_PIN_4, 0, RCU_GPIOH}
#define PH5 (UP_GPIO){GPIOH, GPIO_PIN_5, 0, RCU_GPIOH}
#define PH6 (UP_GPIO){GPIOH, GPIO_PIN_6, 0, RCU_GPIOH}
#define PH7 (UP_GPIO){GPIOH, GPIO_PIN_7, 0, RCU_GPIOH}
#define PH8 (UP_GPIO){GPIOH, GPIO_PIN_8, 0, RCU_GPIOH}
#define PH9 (UP_GPIO){GPIOH, GPIO_PIN_9, 0, RCU_GPIOH}
#define PH10 (UP_GPIO){GPIOH, GPIO_PIN_10, 0, RCU_GPIOH}
#define PH11 (UP_GPIO){GPIOH, GPIO_PIN_11, 0, RCU_GPIOH}
#define PH12 (UP_GPIO){GPIOH, GPIO_PIN_12, 0, RCU_GPIOH}
#define PH13 (UP_GPIO){GPIOH, GPIO_PIN_13, 0, RCU_GPIOH}
#define PH14 (UP_GPIO){GPIOH, GPIO_PIN_14, 0, RCU_GPIOH}
#define PH14 (UP_GPIO){GPIOH, GPIO_PIN_14, 0, RCU_GPIOH}
#define PH15 (UP_GPIO){GPIOH, GPIO_PIN_15, 0, RCU_GPIOH}

#define PI0 (UP_GPIO){GPIOI, GPIO_PIN_0, 0, RCU_GPIOI}
#define PI1 (UP_GPIO){GPIOI, GPIO_PIN_1, 0, RCU_GPIOI}
#define PI2 (UP_GPIO){GPIOI, GPIO_PIN_2, 0, RCU_GPIOI}
#define PI3 (UP_GPIO){GPIOI, GPIO_PIN_3, 0, RCU_GPIOI}
#define PI4 (UP_GPIO){GPIOI, GPIO_PIN_4, 0, RCU_GPIOI}
#define PI5 (UP_GPIO){GPIOI, GPIO_PIN_5, 0, RCU_GPIOI}
#define PI6 (UP_GPIO){GPIOI, GPIO_PIN_6, 0, RCU_GPIOI}
#define PI7 (UP_GPIO){GPIOI, GPIO_PIN_7, 0, RCU_GPIOI}
#define PI8 (UP_GPIO){GPIOI, GPIO_PIN_8, 0, RCU_GPIOI}
#define PI9 (UP_GPIO){GPIOI, GPIO_PIN_9, 0, RCU_GPIOI}
#define PI10 (UP_GPIO){GPIOI, GPIO_PIN_10, 0, RCU_GPIOI}
#define PI11 (UP_GPIO){GPIOI, GPIO_PIN_11, 0, RCU_GPIOI}

typedef struct {
    /**
     @brief GPIO pin with pull-up or pull-down resistor
      \arg        GPIO_PUPD_NONE: floating mode, no pull-up and pull-down resistors
      \arg        GPIO_PUPD_PULLUP: with pull-up resistor
      \arg        GPIO_PUPD_PULLDOWN:with pull-down resistor
     *
     */
    uint32_t pull_up_down;
    /**
     @brief GPIO pin output mode
        \arg        GPIO_OTYPE_PP: push pull mode
        \arg        GPIO_OTYPE_OD: open drain mode
     */
    uint8_t otype;
} UP_GPIO_PARAMS;


// EXTI --------------------------
void EX0_isr();
void EX1_isr();
void EX2_isr();
void EX3_isr();
void EX4_isr();
void EX5_isr();
void EX6_isr();
void EX7_isr();
void EX8_isr();
void EX9_isr();
void EX10_isr();
void EX11_isr();
void EX12_isr();
void EX13_isr();
void EX14_isr();
void EX15_isr();

// TIMER ----------------------------------------------------------------------------

void TM1_isr(void);
void TM2_isr(void);
void TM3_isr(void);
void TM4_isr(void);
void TM5_isr(void);
void TM6_isr(void);
void TM8_isr(void);
void TM9_isr(void);
void TM10_isr(void);
void TM11_isr(void);
void TM12_isr(void);
void TM13_isr(void);

typedef struct {
    uint32_t prescaler; // 分频系数 0-65535
    uint32_t frequency; // 频率, 单位Hz, 与period_ms相反, 2选1
    uint32_t period_ms; // 周期, 单位ms, 与frequency相反, 2选1
    uint8_t disable; // 是否失能
} UP_TIMER_PARAMS;

extern UP_TIMER_PARAMS uc_timer_params_default;

typedef struct{
    uint32_t timer_periph;
    uint16_t channel;
    UP_GPIO uc_gpio;
    uint32_t alt_func_num;
} UP_Timer;

// 记录PWM所有引脚名和对应的复用方法
#define TIMER0_CH0_PA8_AF1  (UP_Timer){TIMER0, TIMER_CH_0, PA8, GPIO_AF_1} 
#define TIMER0_CH0_PE9_AF1  (UP_Timer){TIMER0, TIMER_CH_0, PE9, GPIO_AF_1}
#define TIMER0_CH1_PA9_AF1  (UP_Timer){TIMER0, TIMER_CH_1, PA9, GPIO_AF_1}
#define TIMER0_CH1_PE11_AF1 (UP_Timer){TIMER0, TIMER_CH_1, PE11, GPIO_AF_1}
#define TIMER0_CH2_PA10_AF1 (UP_Timer){TIMER0, TIMER_CH_2, PA10, GPIO_AF_1}
#define TIMER0_CH2_PE13_AF1 (UP_Timer){TIMER0, TIMER_CH_2, PE13, GPIO_AF_1}
#define TIMER0_CH3_PA11_AF1 (UP_Timer){TIMER0, TIMER_CH_3, PA11, GPIO_AF_1}
#define TIMER0_CH3_PE14_AF1 (UP_Timer){TIMER0, TIMER_CH_3, PE14, GPIO_AF_1}

#define TIMER1_CH0_PA0_AF1  (UP_Timer){TIMER1, TIMER_CH_0, PA0, GPIO_AF_1}
#define TIMER1_CH0_PA5_AF1  (UP_Timer){TIMER1, TIMER_CH_0, PA5, GPIO_AF_1}
#define TIMER1_CH0_PA15_AF1 (UP_Timer){TIMER1, TIMER_CH_0, PA15, GPIO_AF_1}
#define TIMER1_CH1_PA1_AF1  (UP_Timer){TIMER1, TIMER_CH_1, PA1, GPIO_AF_1}
#define TIMER1_CH1_PB3_AF1  (UP_Timer){TIMER1, TIMER_CH_1, PB3, GPIO_AF_1}
#define TIMER1_CH2_PA2_AF1  (UP_Timer){TIMER1, TIMER_CH_2, PA2, GPIO_AF_1}
#define TIMER1_CH3_PA3_AF1  (UP_Timer){TIMER1, TIMER_CH_3, PA3, GPIO_AF_1}
#define TIMER1_CH3_PB2_AF1  (UP_Timer){TIMER1, TIMER_CH_3, PB2, GPIO_AF_1}

#define TIMER2_CH0_PA6_AF2  (UP_Timer){TIMER2, TIMER_CH_0, PA6, GPIO_AF_2}
#define TIMER2_CH0_PB4_AF2  (UP_Timer){TIMER2, TIMER_CH_0, PB4, GPIO_AF_2}
#define TIMER2_CH0_PC6_AF2  (UP_Timer){TIMER2, TIMER_CH_0, PC6, GPIO_AF_2}
#define TIMER2_CH1_PA7_AF2  (UP_Timer){TIMER2, TIMER_CH_1, PA7, GPIO_AF_2}
#define TIMER2_CH1_PB5_AF2  (UP_Timer){TIMER2, TIMER_CH_1, PB5, GPIO_AF_2}
#define TIMER2_CH1_PC7_AF2  (UP_Timer){TIMER2, TIMER_CH_1, PC7, GPIO_AF_2}
#define TIMER2_CH2_PB0_AF2  (UP_Timer){TIMER2, TIMER_CH_2, PB0, GPIO_AF_2}
#define TIMER2_CH2_PC8_AF2  (UP_Timer){TIMER2, TIMER_CH_2, PC8, GPIO_AF_2}
#define TIMER2_CH3_PB1_AF2  (UP_Timer){TIMER2, TIMER_CH_3, PB1, GPIO_AF_2}
#define TIMER2_CH3_PC9_AF2  (UP_Timer){TIMER2, TIMER_CH_3, PC9, GPIO_AF_2}

#define TIMER3_CH0_PB6_AF2  (UP_Timer){TIMER3, TIMER_CH_0, PB6, GPIO_AF_2}
#define TIMER3_CH0_PD12_AF2 (UP_Timer){TIMER3, TIMER_CH_0, PD12, GPIO_AF_2}
#define TIMER3_CH1_PB7_AF2  (UP_Timer){TIMER3, TIMER_CH_1, PB7, GPIO_AF_2}
#define TIMER3_CH1_PD13_AF2 (UP_Timer){TIMER3, TIMER_CH_1, PD13, GPIO_AF_2}
#define TIMER3_CH2_PB8_AF2  (UP_Timer){TIMER3, TIMER_CH_2, PB8, GPIO_AF_2}
#define TIMER3_CH2_PD14_AF2 (UP_Timer){TIMER3, TIMER_CH_2, PD14, GPIO_AF_2}
#define TIMER3_CH3_PB9_AF2  (UP_Timer){TIMER3, TIMER_CH_3, PB9, GPIO_AF_2}
#define TIMER3_CH3_PD15_AF2 (UP_Timer){TIMER3, TIMER_CH_3, PD15, GPIO_AF_2}

#define TIMER4_CH0_PA0_AF2  (UP_Timer){TIMER4, TIMER_CH_0, PA0, GPIO_AF_2}
#define TIMER4_CH0_PH10_AF2 (UP_Timer){TIMER4, TIMER_CH_0, PH10, GPIO_AF_2}
#define TIMER4_CH1_PA1_AF2  (UP_Timer){TIMER4, TIMER_CH_1, PA1, GPIO_AF_2}
#define TIMER4_CH1_PH11_AF2 (UP_Timer){TIMER4, TIMER_CH_1, PH11, GPIO_AF_2}
#define TIMER4_CH2_PA2_AF2  (UP_Timer){TIMER4, TIMER_CH_2, PA2, GPIO_AF_2}
#define TIMER4_CH2_PH12_AF2 (UP_Timer){TIMER4, TIMER_CH_2, PH12, GPIO_AF_2}
#define TIMER4_CH3_PA3_AF2  (UP_Timer){TIMER4, TIMER_CH_3, PA3, GPIO_AF_2}
#define TIMER4_CH3_PI0_AF2  (UP_Timer){TIMER4, TIMER_CH_3, PI0, GPIO_AF_2}

#define TIMER7_CH0_PC6_AF3  (UP_Timer){TIMER7, TIMER_CH_0, PC6, GPIO_AF_3}
#define TIMER7_CH0_PI5_AF3  (UP_Timer){TIMER7, TIMER_CH_0, PI5, GPIO_AF_3}
#define TIMER7_CH1_PC7_AF3  (UP_Timer){TIMER7, TIMER_CH_1, PC7, GPIO_AF_3}
#define TIMER7_CH1_PI6_AF3  (UP_Timer){TIMER7, TIMER_CH_1, PI6, GPIO_AF_3}
#define TIMER7_CH2_PC8_AF3  (UP_Timer){TIMER7, TIMER_CH_2, PC8, GPIO_AF_3}
#define TIMER7_CH2_PI7_AF3  (UP_Timer){TIMER7, TIMER_CH_2, PI7, GPIO_AF_3}
#define TIMER7_CH3_PC9_AF3  (UP_Timer){TIMER7, TIMER_CH_3, PC9, GPIO_AF_3}
#define TIMER7_CH3_PI2_AF3  (UP_Timer){TIMER7, TIMER_CH_3, PI2, GPIO_AF_3}

#define TIMER8_CH0_PA2_AF3  (UP_Timer){TIMER8, TIMER_CH_0, PA2, GPIO_AF_3}
#define TIMER8_CH0_PE5_AF3  (UP_Timer){TIMER8, TIMER_CH_0, PE5, GPIO_AF_3}
#define TIMER8_CH1_PA3_AF3  (UP_Timer){TIMER8, TIMER_CH_1, PA3, GPIO_AF_3}
#define TIMER8_CH1_PE6_AF3  (UP_Timer){TIMER8, TIMER_CH_1, PE6, GPIO_AF_3}

#define TIMER9_CH0_PB8_AF3  (UP_Timer){TIMER9, TIMER_CH_0, PB8, GPIO_AF_3}
#define TIMER9_CH0_PF6_AF3  (UP_Timer){TIMER9, TIMER_CH_0, PF6, GPIO_AF_3}
#define TIMER10_CH0_PB9_AF3  (UP_Timer){TIMER10, TIMER_CH_0, PB9, GPIO_AF_3}
#define TIMER10_CH0_PF7_AF3  (UP_Timer){TIMER10, TIMER_CH_0, PF7, GPIO_AF_3}
#define TIMER11_CH0_PB14_AF9 (UP_Timer){TIMER11, TIMER_CH_0, PB14, GPIO_AF_9}
#define TIMER11_CH1_PB15_AF9 (UP_Timer){TIMER11, TIMER_CH_1, PB15, GPIO_AF_9}
#define TIMER11_CH1_PH9_AF9  (UP_Timer){TIMER11, TIMER_CH_1, PH9, GPIO_AF_9}
#define TIMER12_CH0_PF8_AF9  (UP_Timer){TIMER12, TIMER_CH_0, PF8, GPIO_AF_9}
#define TIMER13_CH0_PA7_AF9  (UP_Timer){TIMER13, TIMER_CH_0, PA7, GPIO_AF_9}
#define TIMER13_CH0_PF9_AF9  (UP_Timer){TIMER13, TIMER_CH_0, PF9, GPIO_AF_9}

// USART -------------------------------------------------------------------------------

#define USART_MODE_NONE (0)
#define USART_TRANSMIT_MODE (1 << 0)
#define USART_RECEIVE_MODE  (1 << 1)
#define USART_RECEIVE_TRANSMIT_MODE USART_RECEIVE_MODE | USART_TRANSMIT_MODE

// 声明使能串口接收配置结构体
typedef struct
{
    uint8_t TR_mode;    // 串口发送接收模式  00禁用(0), 01接收(1), 10发送(2), 11发送接收(3)
    uint8_t nvic_irq_pre_priority; // 抢占优先级0-3
    uint8_t nvic_irq_sub_priority; //   子优先级0-3
} UP_USART;

// SPI ----------------------------
typedef struct {
    spi_parameter_struct *spi_init_struct;
    UP_GPIO pin_sck;
    UP_GPIO pin_mosi;
    UP_GPIO pin_miso;
    UP_GPIO pin_nss;
    UP_GPIO pin_io2;
    UP_GPIO pin_io3;
} UP_SPI;

extern UP_SPI uc_spi_default;

// DAC ---------------------------

typedef struct {
    uint32_t triggersource;
    uint32_t wave_mode;
    uint32_t dac_align;
    uint16_t data;
} UP_DAC_PARAMS;

// ADC ---------------------------

typedef struct
{
    uint32_t prescaler; // ADC时钟分频, ADC_ADCCK_PCLK2_DIV8, 参考adc_clock_config参数
    uint32_t sync_mode; // ADC工作模式, ADC_SYNC_MODE_INDEPENDENT, 参考adc_sync_mode_config参数
    uint32_t cont_mode; // ADC连续转换模式, DISABLE, 参考adc_special_function_config参数
    uint32_t scan_mode; // ADC扫描模式, DISABLE, 参考adc_special_function_config参数
    uint32_t data_align; // ADC数据对齐方式, ADC_DATAALIGN_RIGHT, 参考adc_data_alignment_config参数
    uint32_t channel_len; // ADC规则通道长度, 1U, 参考adc_channel_length_config参数
} UP_ADC_PARAMS;

// I2C IIC-----------------------------

typedef struct {
    UP_GPIO scl_gpio;
    uint32_t scl_af;
    UP_GPIO sda_gpio;
    uint32_t sda_af;

    uint32_t clkspeed;
    uint32_t mode ; 
    uint32_t addformat; 
} UP_I2C_PARAMS;

extern UP_I2C_PARAMS uc_i2c_params_default;

#endif // !__UP_CONFIG_H__